home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_shw_switch_doors.cog < prev    next >
Text File  |  1999-11-15  |  7KB  |  233 lines

  1. # Jones 3D Cog Script
  2. #
  3. # shw_general_doors.cog
  4. #
  5. # Generic Door Script
  6. #
  7. # [CMG]
  8. #
  9. # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
  10. # ========================================================================================
  11.  
  12. symbols
  13.     message    startup        
  14.     message    activated        
  15.  
  16.     thing        door0                            linkid=0
  17.     thing        button0        
  18.     thing        button1        
  19.     thing        player                            local
  20.  
  21.     flex        doortime=1.0
  22.     float        doorspeed=1.0                    local
  23.     float        sleepTime=3.0
  24.     int            open=0                            local
  25.     
  26.     vector    vecLightValue                        local
  27.  
  28.     sector    doorSector                            local
  29.  
  30.     sound    click=sol_panel_switch_c.wav        local
  31.     sound    open_squeak=sea_doors_open_c.wav    local
  32.     sound    close_squeak=sea_doors_close_c.wav    local
  33.  
  34. # ---------HAL DOOR STUFF----------
  35.     
  36.     int        notnow=0                            local
  37.     int        alreadytouched=0                    local
  38.     vector    v_dpos                                local # door position
  39.     vector    v_ipos                                local # indy position
  40.     vector    v_idvec                                local # indy-to-door vec
  41.     vector    v_drvec                                local # door right vec
  42.     vector    v_tchdoorPYR                        local
  43.     flex    f_iposcheck                            local # dot result indy relative to door
  44.     flex    dooryaw                                local
  45.     flex    timeratio                            local
  46.     flex    reopentime                            local
  47.     flex    f_arrdoorY                            local # door yaw
  48.     vector    v_arrdoorPYR                        local
  49.     vector    v_closedoorPYR                        local # door aim
  50.     flex    closeangle                            local
  51.  
  52.         # NOTE:  door0 has 4 states...
  53.         # closed        --> open == 0 (init state)
  54.         # opening        --> open == 1
  55.         # open        --> open == 2
  56.         # closing        --> open == 3
  57.  
  58. #subroutines
  59.         
  60.     flex     opendoors                            local
  61.     flex    closedoors                            local
  62.  
  63.  
  64.  
  65. end
  66.  
  67. # ========================================================================================
  68.  
  69. code
  70.  
  71. startup:
  72.     player = GetLocalPlayerThing();
  73.     doorSector = GetThingSector(door0);
  74.     SetSectorAdjoins(doorSector, 0);
  75.     #v_closedoorPYR = GetThingLVecPYR(door0);
  76.     return;
  77.  
  78. # ........................................................................................
  79.  
  80. activated:
  81.  
  82.         if (notnow == 1) return;
  83.         if (IsThingMoving(door0)) return;
  84.         if (getSenderRef() == button0)
  85.         {
  86.                 notnow=1;
  87.                 # disable player control
  88.                 SetActorFlags(player, 0x200000);
  89.                 DeselectWeapon(player); # stow any weapon or lighter
  90.                 Sleep(0.5); # wait a beat
  91.                 SetSectorAdjoins(doorSector, 1);
  92.                 # animate the player
  93.                 PlayMode(player, 60, 0);
  94.                 Sleep(0.25);
  95.                 # Player regains control
  96.                 ClearActorFlags(player, 0x200000);
  97.                 # play sounds, move the buttons and door
  98.                 MoveToFrame(button0, 1, 1);
  99.                 MoveToFrame(button1, 1, 1);
  100.                 PlaySoundThing(click, button0, 1, 3, 10, 0x0);
  101.                 Sleep(0.25);
  102.                 Rotate(door0, 90, 1, doorspeed);
  103.                 PlaySoundThing(open_squeak, door0, 1, 3, 10, 0x0);
  104.                 waitforstop(door0);
  105.                 sleep(sleepTime);
  106.                 Rotate(door0, -90, 1, doorspeed);
  107.                 PlaySoundThing(close_squeak, door0, 1, 3, 10, 0x0);
  108.                 waitforstop(door0);
  109.                 PlaySoundThing(click, door0, 1, 3, 10, 0x0);
  110.                 MoveToFrame(button0, 0, 4);
  111.                 MoveToFrame(button1, 0, 4);
  112.                 SetSectorAdjoins(doorSector, 0);
  113.                 notnow = 0;
  114.                 return;
  115.             
  116.         }
  117.     else
  118.         
  119.         if (GetSenderRef() == button1)
  120.         {
  121.             if (IsThingMoving(door0)) return;
  122.             {
  123.                 notnow=1;
  124.                 SetActorFlags(player, 0x200000);
  125.                 DeselectWeapon(player); # stow any weapon or lighter
  126.                 Sleep(0.5); # wait a beat
  127.                 SetSectorAdjoins(doorSector, 1);
  128.                 PlayMode(player, 60, 0);
  129.                 Sleep(0.5);
  130.                 ClearActorFlags(player, 0x200000);
  131.                 MoveToFrame(button0, 1, 1);
  132.                 MoveToFrame(button1, 1, 1);
  133.                 PlaySoundThing(click, button1, 1, 3, 10, 0x0);
  134.                 Sleep(0.25);
  135.                 Rotate(door0, -90, 1, doorspeed);
  136.                 PlaySoundThing(open_squeak, door0, 1, 3, 10, 0x0);
  137.                 waitforstop(door0);
  138.                 sleep(sleepTime);
  139.                 Rotate(door0, 90, 1, doorspeed);
  140.                 PlaySoundThing(close_squeak, door0, 1, 3, 10, 0x0);
  141.                 waitforstop(door0);
  142.                 PlaySoundThing(click, door0, 1, 3, 10, 0x0);
  143.                 MoveToFrame(button0, 0, 4);
  144.                 MoveToFrame(button1, 0, 4);
  145.                 SetSectorAdjoins(doorSector, 0);
  146.                 notnow = 0;
  147.                 return;
  148.             }
  149.         }
  150.         
  151. # ........................................................................................
  152. arrived:
  153.  
  154.  
  155.     if (GetSenderRef() == door0 && open == 1)
  156.     {
  157.         open = 2;                             # door is now open
  158.         SetTimer(sleepTime);
  159.     }
  160.     if (GetSenderRef() == door0 && open == 3)
  161.     {
  162.         if(alreadytouched == 1) return;
  163.         movetoframe(button0, 0, 1);
  164.         movetoframe(button1, 0, 1);
  165.         v_arrdoorPYR = GetThingLVecPYR(door0);
  166.         f_arrdoorY = Truncate(VectorY(v_arrdoorPYR));    # to lowest integer degree
  167.         if (f_arrdoorY == 0)
  168.         {
  169.             SetThingLVecPYR(door0, v_closedoorPYR); # slam it closed for sure
  170.         }
  171.         open = 0;                             # door is now closed
  172.         notnow=0;
  173.     }
  174.     return;
  175.  
  176. # ........................................................................................
  177. touched:
  178.     if (GetSenderRef() == door0 && open == 3)
  179.     {
  180.     alreadytouched = 1; # do once only
  181.         # check if Indy is touching back side of door...
  182.         v_dpos = GetThingPos(door0); # door hinge
  183.         v_ipos = GetThingPos(player); # our hero
  184.          v_idvec = VectorNorm(VectorSub(v_dpos, v_ipos)); # direction between indy & door 
  185.         v_drvec = GetThingLVec(door0);             # check 90 to door plane
  186.         f_iposcheck = VectorDot(v_idvec, v_drvec);     # places indy in- or outside door
  187.     if (f_iposcheck > 0)
  188.     {
  189.     # Don't re-open if Indy is touching back side...
  190.     return;
  191.     }    
  192.     open = 1;                             # door is opening again
  193.     StopThing(door0);
  194. #    Print("door is blocked");
  195.     Sleep(0.1); # let engine update
  196.     v_tchdoorPYR = GetThingLVecPYR(door0);
  197.     closeangle = (Abs(VectorY(v_closedoorPYR)) + 90);
  198.     dooryaw = (closeangle - Abs(VectorY(v_tchdoorPYR)));    # how far is door open?
  199. #    printflex(dooryaw);
  200.     timeratio = (abs(dooryaw) / 90);                 # what percentage?
  201.     reopentime = ( doortime * timeratio);         # calculate time
  202.     Rotate(door0, dooryaw, 1, reopentime);         # re-open 
  203.     }
  204.     return;
  205.  
  206. # ........................................................................................
  207. timer:
  208.     call CloseDoors;
  209.     return;
  210.  
  211. # ........................................................................................
  212. OpenDoors:
  213.     Rotate(door0, 90, 1, doortime);
  214.     #PlaySoundThing(opensnd, door0, 1, 5, 10, 0);
  215.     open = 1;
  216.     alreadytouched = 0; # init every time door opens
  217.     return;    
  218.     
  219.  
  220.     
  221. # ........................................................................................
  222. CloseDoors:
  223.     Rotate(door0, -90, 1, doortime);
  224.     #PlaySoundThing(closesnd, door0, 1, 5, 10, 0);
  225.     open = 3;
  226.     alreadytouched = 0; # Indy can stop it again
  227.     return;
  228.  
  229. # ........................................................................................
  230.  
  231. end
  232.  
  233.